package com.webrtc.demo.contacts.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.webrtc.demo.R
import com.webrtc.demo.model.Contacts
import kotlinx.android.synthetic.main.item_contacts_list.view.*

class ContactsListAdapter :
    BaseQuickAdapter<Contacts, BaseViewHolder>(R.layout.item_contacts_list) {

    init {
        addChildClickViewIds(R.id.messageIv, R.id.videoIv, R.id.editIv)
    }

    override fun convert(helper: BaseViewHolder, item: Contacts) {
        helper.itemView.run {
            val name = if (!item.nickname.isNullOrEmpty()) {
                "(" + item.nickname + ")" + item.uid
            } else {
                item.uid
            }
            nameTv.text = name
            item.lastMessage?.let {
                messageTv.visibility = View.VISIBLE
                messageTv.text = it
            } ?: run {
                messageTv.visibility = View.GONE
            }
        }
    }

}